﻿using Infrastructure.Attribute;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.mes.md;
using ZR.Service.mes.md.IService;

namespace ZR.Service.mes.md
{
    [AppService(ServiceType = typeof(IMdWorksortService), ServiceLifetime = LifeTime.Transient)]
    public class MdWorksortService : BaseService<MdWorksort>, IMdWorksortService
    {

        public int AddWorksort(MdWorksort workshop)
        {
            return Add(workshop);


        }

        public int deleteWorksort(int[] ids)
        {
            return Delete(ids);
        }

        public (int, List<MdWorksort>) GetAll(string worksortCode, string worksortName, int pageNum, int pageSize)
        {
            int totalNum = 0;
            var predicate = Expressionable.Create<MdWorksort>()
                .AndIF(!string.IsNullOrEmpty(worksortCode), it => it.WorksortCode.Contains(worksortCode))
                .AndIF(!string.IsNullOrEmpty(worksortName), it => it.WorksortName.Contains(worksortName))
                .ToExpression();


            List<MdWorksort> data = Context.Queryable<MdWorksort>().Where(predicate).ToPageList(pageNum, pageSize, ref totalNum);

            return (totalNum, data);
        }

        public int UpdateWorksort(MdWorksort workshop)
        {
            return Update(workshop, true);
        }
    }
}
